﻿@{
    ViewBag.Title = "用户管理";
}
<link href="~/Content/bootstrap-table-develop/dist/bootstrap-table.min.css" rel="stylesheet" />

<div class="page animation-fade" id="app">
    <div class="page-content">
        <!--高级检索部分-->
        <div class="panel" id="panelSearch">
            <div class="panel-heading">
                <h3 class="panel-title">高级检索</h3>
            </div>
            <div class="panel-body">
                <form action="javascript:void(0)" class="form-row">
                    <div class="col-sm-3">
                        <h4 class="example-title">登录名</h4>
                        <input type="text" class="form-control" name="userLoginName" id="userLoginName" placeholder="请输入登录名">
                    </div>
                    <div class="col-sm-3">
                        <h4 class="example-title">用户邮箱</h4>
                        <input type="text" class="form-control" name="userEmail" id="userEmail" placeholder="请输入邮箱">
                    </div>
                    <div class="col-sm-3">
                        <h4 class="example-title">用户名</h4>
                        <input type="text" class="form-control" name="userName" id="userName" placeholder="请输入用户名">
                    </div>
                </form>
            </div>
            <div class="panel-footer text-right">
                <button class="btn btn-primary" onclick="bstApi.search()" id="btn_search">查询</button>&nbsp;&nbsp;
                <button class="btn btn-success" onclick="bstApi.resetSearch()">重置</button>&nbsp;&nbsp;
                <button class="btn btn-danger" onclick="bstApi.panelSearch()">关闭</button>
            </div>
        </div>
        <!--列表-->
        <div class="panel">
            <div class="panel-heading">
                <div class="col-sm-12 pt-3">
                    <ul id="adminTools">
                        <li>
                            <a href=""><i class="fa fa-rotate-right"></i>&nbsp;刷新</a>
                        </li>
                        <li data-power="Search" name="search">
                            <a href="javascript:;" onclick="bstApi.panelSearch()"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </li>
                        <li data-power="Add" name="add">
                            <a href="javascript:;" id="a-add" onclick="$.userdata.form('add')"><i class="fa fa-plus"></i>&nbsp;添加</a>
                        </li>
                        <li data-power="Edit" name="edit" style="display:none;">
                            <a href="javascript:;" id="a-edit" onclick="$.userdata.form('edit')"><i class="fa fa-pencil"></i>&nbsp;修改</a>
                        </li>
                        <li data-power="Delete" name="delete" style="display:none;">
                            <a href="javascript:;" id="a-remove" onclick="$.userdata.remove()"><i class="fa fa-trash"></i>&nbsp;删除</a>
                        </li>
                        <li data-power="GetExcel" name="getExcel">
                            <a href="javascript:;" target="_blank"><i class="fa fa-file-excel-o"></i>&nbsp;导出 Excel</a>
                        </li>
                        <li data-power="Print" name="print">
                            <a href="javascript:;" target="_blank"><i class="fa fa-file-text"></i>&nbsp;打印</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="panel-body container-fluid p-10">
                <!--表格-->
                <table class="table table-hover" id="bootStrapTable"></table>
            </div>
        </div>
    </div>
</div>
<script src="~/Content/bootstrap-table-develop/dist/bootstrap-table.min.js"></script>
<script src="~/Content/bootstrap-table-develop/dist/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="~/Content/CustomJs/BootStrapTable.js"></script>
<script type="text/javascript">
    (function ($) {
        $.userdata = {
            load:function () {
                var columns = [{
                    field: 'gid',
                    title: 'ID',
                    visible: false
                }, {
                    field: 'userLoginName',
                    title: '用户账号',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                }, {
                    field: 'userEmail',
                    title: '邮箱',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                }, {
                    field: 'userName',
                    title: '用户名',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                }, {
                    field: 'createTime',
                    title: '添加时间',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                 }, {
                    field: 'finallyTime',
                    title: '修改时间',
                    align: 'center',
                    valign: 'middle',
                    sortable: true
                }];
                var url = '/SysUser/GetUsers';

                var adminBootStrapTable = bstApi.bootStrapTable({
                    url: url,
                    idField: 'gid',
                    columns: columns
                });

                //$.ajax({
                //    type: 'POST',
                //    url: url,
                //    data: { rows: 10 },
                //    dataType: 'JSON',
                //    success: function (datas) {
                //        console.log(datas);
                //    }
                //});
            },
            //打开表单
            form: function (tag) {
                var rows = bstApi.selectRows();
                var url = "@Url.Action("Info")";
                if (tag == "add") {
                    url = url + "/?ID=";
                } else {
                    url = url + "/?ID=" + rows[0].gid;
                }
                bstApi.form({
                    id: "",
                    parentIframeName: "",
                    url: url,
                    width: "600px",
                    height: "600px",
                    btn: false,
                });
            },
            //删除数据
            remove: function () {
                bstApi.delete('@Url.Action("Delete")', function () {
                    $.userdata.refresh();
                    console.log("删除完成!");
                });
            },
            //刷新列表数据
            refresh: function (data) {
                bstApi.refresh(data);
            },
            //导出excel
            exportExcel: function () {
                bstApi.exportExcel('@Url.Action("ExportExcel")');
            },
            //打印
            print: function () {
                bstApi.print('@Url.Action("Print")');
            },
        };

        $(function () {
            $.userdata.load();
        });
    })(jQuery)
</script>
